//JavaScript Framework 2.0 Code
try{
Type.registerNamespace('com.yonyou.ncmm_pac_pda.LoginSettingPageController');
com.yonyou.ncmm_pac_pda.LoginSettingPageController = function() {
    com.yonyou.ncmm_pac_pda.LoginSettingPageController.initializeBase(this);
    this.initialize();
}
function com$yonyou$ncmm_pac_pda$LoginSettingPageController$initialize(){
    var host = $cache.read("host") ? $cache.read("host") : "";
    var port = $cache.read("port") ? $cache.read("port") : "";
    var groupcode = $cache.read("groupcode") ? $cache.read("groupcode") : "";
    var factory = $cache.read("factory") ? $cache.read("factory") : "";
    var stockorg = $cache.read("stockorg") ? $cache.read("stockorg") : "";
    var stordoc = $cache.read("stordoc") ? $cache.read("stordoc") : "";
    var enabledmodule = $cache.read("enabledmodule") ? $cache.read("enabledmodule") : 0;
    
    var settinginfo = {"host":host,"port":port,"groupcode":groupcode,"factory":factory,"stockorg":stockorg,"stordoc":stordoc,"enabledmodule":enabledmodule};
	
    $ctx.push(settinginfo);
}
    
function com$yonyou$ncmm_pac_pda$LoginSettingPageController$evaljs(js){
    eval(js)
}
// 打开仓库选择界面
function com$yonyou$ncmm_pac_pda$LoginSettingPageController$btnstock_onclick(sender, args){
	openRefPage({reftype:"PDASTORDOC", reftitle:"仓库", refpkfld:"pk_stordoc"},"stordoc");
}
// 打开库存组织选择界面
function com$yonyou$ncmm_pac_pda$LoginSettingPageController$btnstockorg_onclick(sender, args){
	openRefPage({reftype:"PDASTOCKORG", reftitle:"库存组织", refpkfld:"pk_stockorg"},"stockorg");
}

function com$yonyou$ncmm_pac_pda$LoginSettingPageController$btnback_onclick(sender, args){
	$view.close();
}
function com$yonyou$ncmm_pac_pda$LoginSettingPageController$btntestconn_onclick(sender, args){
	var host = $id("txthost").get("value");
	var port = $id("txtport").get("value");
	
	if (!host || !port) {
		$toast("请先设置服务器信息");
		return;
	}
	var url = 'http://' + host + ':' + port + '/service/exbdlogin';
	$js.showLoadingBar();
	$service.call('MMHttpService.post', {
		'url' : url,
		'data' : {nccontext:{user:"1", password:"1", exsystemcode:'mmapp', devicecode:'pda001'}},
		'callback' : 'testCallBack()',
		'header' : {
			'Content-Type' : 'application/json'
		}
	},true);
}
function com$yonyou$ncmm_pac_pda$LoginSettingPageController$btnsave_onclick(sender, args){
	var host = $id("txthost").get("value");
	var port = $id("txtport").get("value");
	$cache.write("host", host);
	$cache.write("port", port);
	
	var groupcode = $id("txtgroupcode").get("value");
	$cache.write("groupcode", groupcode);
	
	$cache.write("factory", $ctx.get("factory"));
	$cache.write("stockorg", $ctx.get("stockorg"));
	$cache.write("stordoc", $ctx.get("stordoc"));
	
	$cache.write("enabledmodule", $id("tbgenabledmodule").get("selectedvalue"));
	
	$view.close();
}

function com$yonyou$ncmm_pac_pda$LoginSettingPageController$wpanelsetting_onload(sender, args){
	/*var host = $cache.read("host") ? $cache.read("host") : "";
    var port = $cache.read("port") ? $cache.read("port") : "";
    var groupcode = $cache.read("groupcode") ? $cache.read("groupcode") : "";
    var factory = $cache.read("factory") ? $cache.read("factory") : "";
    var stockorg = $cache.read("stockorg") ? $cache.read("stockorg") : "";
    var stordoc = $cache.read("stordoc") ? $cache.read("stordoc") : "";
    
    var settinginfo = {"host":host,"port":port,"groupcode":groupcode,"factory":factory,"stockorg":stockorg,"stordoc":stordoc};

    $ctx.push(settinginfo);*/
}
com.yonyou.ncmm_pac_pda.LoginSettingPageController.prototype = {
    wpanelsetting_onload : com$yonyou$ncmm_pac_pda$LoginSettingPageController$wpanelsetting_onload,
    btnsave_onclick : com$yonyou$ncmm_pac_pda$LoginSettingPageController$btnsave_onclick,
    btntestconn_onclick : com$yonyou$ncmm_pac_pda$LoginSettingPageController$btntestconn_onclick,
    btnback_onclick : com$yonyou$ncmm_pac_pda$LoginSettingPageController$btnback_onclick,
    btnstockorg_onclick : com$yonyou$ncmm_pac_pda$LoginSettingPageController$btnstockorg_onclick,
    btnstock_onclick : com$yonyou$ncmm_pac_pda$LoginSettingPageController$btnstock_onclick,
    initialize : com$yonyou$ncmm_pac_pda$LoginSettingPageController$initialize,
    evaljs : com$yonyou$ncmm_pac_pda$LoginSettingPageController$evaljs
};
com.yonyou.ncmm_pac_pda.LoginSettingPageController.registerClass('com.yonyou.ncmm_pac_pda.LoginSettingPageController',UMP.UI.Mvc.Controller);
}catch(e){$e(e);}
// 打开参照页面
function openRefPage(refinfo, ctxkey) {
	var username = $cache.read("username");
    var password = $cache.read("password");
    if (!username || !password) {
    	$toast("请先登录");
    	return;
    }
    $view.open({
        viewid: "com.yonyou.ncmm_pac_pda.RefPage",//目标页面
        isKeep: "true",//打开新页面的同时是否保留当前页面，true为保留，false为不保留
        data : refinfo,
        callback : function() {
        	var refdata = $param.getJSONObject("data");
        	$ctx.put(ctxkey,refdata.billinfo);
        	$ctx.dataBind();
        }
    });
}

function testCallBack(){
	$js.hideLoadingBar();
	var result = $ctx.param("result");
	if (!result || result == "") {
		$toast("测试未通过");
		return;
	}
	
	$toast("测试通过");
}
